package com.leaf.u_spring.chapter12;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class RedisConfig {

	/**
	 * 创建连接工厂 回向localhost上的6379端口创建连接
	 * @return
	 */
	@Bean
	public RedisConnectionFactory redisCF() {
		return new JedisConnectionFactory();
	}
	
	/**
	 * 插件自定义配置的连接工厂
	 * @return
	 */
//	@Bean
//	public RedisConnectionFactory redisCF() {
//		JedisConnectionFactory cf = new JedisConnectionFactory();
//		cf.setHostName("redis-server");
//		cf.setPort(6379);
//		cf.setPassword("111111");
//		
//		return new JedisConnectionFactory();
//	}
	
	@Bean
	public RedisTemplate<String, Product> redisTemplate(RedisConnectionFactory cf) {
		RedisTemplate<String, Product> redis = new RedisTemplate<String, Product>();
		redis.setConnectionFactory(cf);
		return redis;
	}
	
}
